package com.huping.mapper;

import com.huping.pojo.Course;
import com.huping.pojo.Homework;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface HomeworkMapper {

    @Insert("insert into homework (teacher_id, course_id , name, start_time, end_time, profile,method,standard_answer,huping_start_time,huping_end_time,type,anonymous) VALUES " +
            "(#{teacherId},#{courseId},#{name},#{startTime},#{endTime},#{profile},#{method},#{standardAnswer},#{hupingStartTime},#{hupingEndTime},#{type},#{anonymous})")
    public int homeworkInsert(Homework homework);

    @Select("select *  from homework where homework_id=#{homeworkId}")
    public Homework getHomeworkDetail(int homeworkId);
    // public List<Map<String ,Object>> getHomeworkDetail(String courseId,String courseName,String homeworkName,String teacher);

    public List<Map<String, Object>> teacherHomeworkSelect(String userid, String courseId, String courseName, String homeworkName);

    public List<Map<String, Object>> studentHomeworkSelect(String userid, String courseId, String courseName, String homeworkName, String teacher);

    @Select("select file from homework where homework_id=#{homeworkId}")
    public String getHomeworkFile(Integer homeworkId);

    @Update("update homework set file=#{fileListStr} where homework_id=#{homeworkId}")
    public int updateHomeworkFile(Integer homeworkId,String fileListStr);

    @Update("update homework set name=#{name},start_time=#{startTime},end_time=#{endTime},method=#{method},profile=#{profile},standard_answer=#{standardAnswer} ,type=#{type},huping_start_time=#{hupingStartTime},huping_end_time=#{hupingEndTime},anonymous=#{anonymous} where homework_id=#{homeworkId}")
    public int homeworkUpdate(Homework homework);

    @Select("select max(homework_id) from homework ")
    public int getNumberOfHomework();

    @Update("update homework set method=#{method} where homework_id=#{homeworkId}")
    public  void  setMethod(Integer homeworkId,String method);

    @Select("select method from homework where homework_id=#{homeworkId}")
    public  String getMethod(Integer homeworkId);
    @Select("select type from homework where homework_id=#{homeworkId}")
    String getHomeworkTypeByHomeworkId(Integer HomeworkId);

    @Select("select name,start_time startTime,end_time endTime,method,profile,file,standard_answer standardAnswer,huping_start_time hupingStartTime,huping_end_time hupingEndTime ,type  from homework where teacher_id=#{userid} and course_id=#{courseId}")
    List<Map<String,Object>>  teacherGetAllHomework(String userid,String courseId);

    @Update("update homework set similarity=#{resultJSONStr} where homework_id=#{homeworkId}")
    void updateSimilarity(String resultJSONStr, Integer homeworkId);

    @Select("select similarity from homework where homework_id=#{homeworkId}")
    String getSimilarityByHomeworkId(Integer homeworkId);

    @Select("select anonymous from homework where homework_id=#{homeworkId}")
    public String getAnonymous(Integer homeworkId);
}
